/**
 * 文件名：WithDrawFacadeImpl.java
 *
 * 创建人：Fyh - 1009173473@qq.com
 *
 * 创建时间：2019年1月10日 下午2:49:38
 *
 * 版权所有：南京植百汇智能科技服务有限公司
 */
package com.z100h.supplychain.evidence.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.facade.FacadeException;
import com.z100h.supplychain.core.EvidenceState;
import com.z100h.supplychain.core.EvidenceType;
import com.z100h.supplychain.core.biz.entity.CommonEvidence;
import com.z100h.supplychain.core.process.AbstractWithdrawProcess;
import com.z100h.supplychain.evidence.entity.Withdraw;
import com.z100h.supplychain.evidence.facade.WithDrawFacade;
import com.z100h.supplychain.evidence.service.WithdrawService;

/**
 * [描述信息：说明类的基本功能]
 *
 * @author Fyh - 1009173473@qq.com
 * @version 1.0 Created on 2019年1月10日 下午2:49:38
 */
@Service
public class WithDrawFacadeImpl extends AbstractWithdrawProcess<Withdraw> implements WithDrawFacade<Withdraw> {

	@Autowired
	private WithdrawService withdrawService;

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.z100h.supplychain.core.process.AbstractWithdrawProcess#createEvidence(com.z100h.supplychain.core.Evidence, com.z100h.supplychain.core.EvidenceState)
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年1月10日 下午2:52:47
	 */
	@Override
	protected String createEvidence(Withdraw evidence, EvidenceState evidenceState) {
		CommonEvidence commonEvidence = new CommonEvidence(EvidenceType.WITHDRAW, evidenceState);
		// 插入主表凭证
		commonEvidenceService.save(commonEvidence);

		// 插入转库凭证
		evidence.setEvidenceId(commonEvidence.getId());
		withdrawService.save(evidence);
		return commonEvidence.getId();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.z100h.supplychain.core.process.AbstractWithdrawProcess#changeResourceWithEvidence(com.z100h.supplychain.core.Evidence, java.util.List)
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年1月10日 下午2:52:47
	 */
	@Override
	protected void changeResourceWithEvidence(Withdraw evidence, List<String> resourceIds) {
		resourceService.updateResourceToWarehouseId(resourceIds, evidence.getWarehouseId());

	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.z100h.supplychain.evidence.facade.WithDrawFacade#withdrawProcess(java.util.List, java.lang.Object)
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年1月10日 下午2:52:47
	 */
	@Override
	@Transactional(readOnly = false)
	public void withdrawProcess(List<String> resourceIds, Withdraw evidence) throws Throwable {
		try {
			process(resourceIds, evidence);
		} catch (FacadeException e) {
			logger.info(e.getMessage());
			throw new FacadeException(e);
		}
	}
}
